<template>
  <div>
    <el-dialog :title="dialogData.title"
               :visible.sync="dialogData.show"
               center
               @close="$emit('closedialog')"
               :close-on-click-modal='false'
               width="90%">
      <el-form :model="formdata"
               label-position="right"
               ref="formdata"
               label-width="150px"
               :rules='rules'>
        <el-form-item label="服务名称："
                      prop="name">
          <el-input v-model="formdata.name"
                    maxlength="50"
                    autocomplete="off"
                    style="width:50%"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="所属分类："
                      prop="healthRiskTypeId">
          <el-select v-model="formdata.healthRiskTypeId"
                     clearable
                     style="width:50%">
            <el-option v-for="item in healthRiskType"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签：">
          <el-input v-model="formdata.label"
                    maxlength="50"
                    autocomplete="off"
                    style="width:50%"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="列表图片："
                      prop="imageUrl">
          <el-upload class="avatar-uploader"
                     :action="imageUploadUrl"
                     :show-file-list="false"
                     accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                     :on-success="handleAvatarSuccess"
                     :before-upload="beforeAvatarUpload">
            <img v-if="formdata.imageUrl"
                 :src="formdata.imageUrl"
                 class="avatar">
            <i v-else
               class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="详情图片："
                      prop="detailImageUrl">
          <el-upload multiple
                     :limit='6'
                     :action="imageUploadUrl"
                     accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                     list-type="picture-card"
                     :on-success="handlePictureCardPreview"
                     :file-list='formdata.detailImage'
                     :on-exceed='onexceed'
                     :on-remove='onremove'
                     :before-upload="beforeAvatarUpload">
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="服务选项111111："
                      prop="itemList">
          <el-button type="success"
                     @click="handleAdd(0)">新 增 一 项</el-button>
          <el-table :data="formdata.itemList"
                    style="width: 100%"
                    border
                    class="mt-20">
            <el-table-column prop="number"
                             label="价格（元）">
              <template slot-scope="scoped">
                <el-input-number :min="0"
                                 :precision="2"
                                 :controls="false"
                                 v-model="scoped.row.price"
                                 type="number"
                                 placeholder="请输入价格"
                                 class="w-200"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="num"
                             label="数量">
              <template slot-scope="scoped">
                <el-input-number :min="0"
                                 :precision="0"
                                 :controls="false"
                                 v-model="scoped.row.num"
                                 type="number"
                                 placeholder="非必填"
                                 class="w-200"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="unit"
                             label="单位">
              <template slot-scope="scoped">
                <el-select v-model="scoped.row.unit"
                           clearable
                           placeholder="请选择单位">
                  <el-option label="小时"
                             :value="1"></el-option>
                  <el-option label="次"
                             :value="2"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="detectFee"
                             label="检测分成费用">
              <template slot-scope="scoped">
                <el-input-number :min="0"
                                 :precision="2"
                                 :controls="false"
                                 v-model="scoped.row.detectFee"
                                 placeholder="请输入检测分成费用"
                                 class="w-200"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="extendFee"
                             label="推广分成">
              <template slot-scope="scoped">
                <el-input-number :min="0"
                                 :precision="2"
                                 :controls="false"
                                 v-model="scoped.row.extendFee"
                                 placeholder="请输入推广分成费用"
                                 class="w-200"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="option"
                             label="操作"
                             width="100">
              <template slot-scope="scoped">
                <el-button type="text"
                           @click='deleteOne1(scoped.$index,formdata.itemList,2)'>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="标配服务："
                      prop="standardService">
          <el-input v-model="formdata.standardService"
                    maxlength="500"
                    show-word-limit
                    type="textarea"
                    :rows="4"
                    autocomplete="off"
                    style="width:50%"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="服务医院："
                      prop="hospitalList">
          <!-- <template slot-scope="row"> -->
          <Select v-model="formdata.hospitalList"
                  filterable
                  multiple
                  remote
                  clearable
                  placeholder="请输入医院名称"
                  style="width:50%"
                  :remote-method="gethospitalList"
                  @on-change="changeHospital">
            <Option v-for="option in options1"
                    :value="option.hospitalId"
                    :label="option.name"
                    :key="option.hospitalId">{{option.name}}</Option>
          </Select>
          <!-- </template> -->
        </el-form-item>

        <el-form-item label="是否是重点合作医院："
                      prop="emphasisHospital"
                      label-width="200px">
          <el-checkbox-group v-model="emphasisHospital">
            <el-checkbox v-for="(item, index) in emphasisHospitalList"
                         :label="item.hospitalId"
                         :checked="Boolean(item.emphasisHospital)"
                         @change="checkboxItem(index, item)"
                         :key="item.hospitalId">{{item.hospitalName}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="可适用的健康风险筛查与监测范围："
                      prop="rangeContent">
          <el-input v-model="formdata.rangeContent"
                    maxlength="500"
                    :rows="4"
                    type="textarea"
                    autocomplete="off"
                    show-word-limit
                    style="width:50%"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="检测项目配置11："
                      prop="detectList">
          <el-button type="success"
                     @click="handleAdd(1,true)">新 增 一 项</el-button>
          <el-table :data="formdata.detectList"
                    style="width: 100%"
                    class="mt-20"
                    border>
            <el-table-column label="服务选项">
              <template slot-scope="scoped">
                这是每组价格项的id= {{scoped.row.healthCheckPackageItemId}}
                <el-select v-model="scoped.row.price"
                           placeholder="请选择"
                           clearable
                           @change="(value)=>{updataCheckProjectPrice(value,scoped.$index)}">
                  <el-option v-for="(item,index) in formdata.itemList"
                             :key="index"
                             :label="`${(item.price || '')+'元'+'/'+(item.num || '')+((item.unit==1?'小时':'次') || '')}`"
                             :value="item.price"></el-option>
                </el-select>

              </template>
            </el-table-column>
            <el-table-column prop="name"
                             label="检查项目">
              <template slot-scope="scoped">
                这是行id ={{scoped.row.id}}
                <el-input v-model="scoped.row.name"
                          placeholder="请输入检查项目"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="deviceIdList"
                             label="检测指标">
              <template slot-scope="scoped">
                <el-select v-model="scoped.row.deviceIdList"
                           filterable
                           multiple
                           clearable
                           placeholder="请输入检测指标">
                  <el-option v-for="(option, index) in dataList"
                             :value="option.id"
                             :key="index"
                             :label="option.name"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="count"
                             label="时长/次数">
              <template slot-scope="scoped">
                <el-input-number :min="0"
                                 :precision="0"
                                 :controls="false"
                                 v-model="scoped.row.count"
                                 type="number"
                                 style="width:100%"
                                 placeholder="请选择时长/次数"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column prop="unit"
                             label="单位">
              <template slot-scope="scoped">
                <el-select v-model="scoped.row.unit"
                           clearable
                           placeholder="请选择单位">
                  <el-option label="小时"
                             :value="1"></el-option>
                  <el-option label="次"
                             :value="2"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="suggest"
                             label="频率">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.suggest"
                          placeholder="非必填"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="option"
                             label="操作">
              <template slot-scope="scoped">
                <el-button type="text"
                           @click='deleteOne1(scoped.$index,formdata.detectList,1)'>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="分成设置："
                      prop="split"
                      label-width="210px">
          <el-radio v-model="formdata.split"
                    :label="0">报告不拆分</el-radio>
          <el-radio v-model="formdata.split"
                    :label="1">报告拆分</el-radio>
        </el-form-item>
        <el-form-item label="是否是特殊筛查项目："
                      prop="specialItem"
                      label-width="210px"
                      v-if="formdata.split === 0">
          <el-radio v-model="formdata.specialItem"
                    :label="0">否</el-radio>
          <el-radio v-model="formdata.specialItem"
                    :label="1">是</el-radio>
        </el-form-item>
        <el-form-item label="是否执行分析复核流程："
                      prop="reCheck"
                      label-width="210px"
                      v-if="formdata.split === 0 && formdata.specialItem === 1">
          <el-radio v-model="formdata.reCheck"
                    :label="0">否</el-radio>
          <el-radio v-model="formdata.reCheck"
                    :label="1">是</el-radio>
        </el-form-item>

        <template v-if="formdata.split === 0 && formdata.reCheck === 1">
          <el-form-item label="分析分成：">
            <el-radio-group v-model="setType"
                            @change="changeSetType">
              <el-radio-button :label="0">医 师</el-radio-button>
              <el-radio-button :label="2">技 师</el-radio-button>
              <el-radio-button :label="7">检验师</el-radio-button>
            </el-radio-group>

            <!-- 医 师 -->
            <template v-if="setType === 0">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                              placeholder="请输入主任医师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName2"
                                 label="副主任医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                              class="w-150"
                              placeholder="请输入副主任医师"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName3"
                                 label="主治医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                              class="w-150"
                              placeholder="请输入主治医师"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName4"
                                 label="住院医师"
                                 align="center">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                              class="w-150"
                              placeholder="请输入住院医师"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName5"
                                 label="公共卫生执业医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][4].price"
                              placeholder="请输入公共卫生执业医师"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </template>
            <!-- 技师 -->
            <template v-if="setType === 2">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                              placeholder="请输入主任技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="副主任技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                              placeholder="请输入副主任技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主管技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                              placeholder="请输入主管技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                              placeholder="请输入技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </template>
            <!-- 检验师 -->
            <template v-if="setType === 7">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                              placeholder="请输入主任检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="副主任检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                              placeholder="请输入副主任检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主管检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                              placeholder="请输入主管检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                              placeholder="请输入检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-form-item>
          <!-- 复核分成 -->
          <el-form-item label="复核分成：">
            <el-radio-group v-model="setCheckType"
                            @change="changeSetCheckType">
              <el-radio-button :label="0">医 师</el-radio-button>
              <el-radio-button :label="2">技 师</el-radio-button>
              <el-radio-button :label="7">检验师</el-radio-button>
            </el-radio-group>
            <!-- 医 师 -->
            <template v-if="setCheckType === 0">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][0].price"
                              placeholder="请输入主任医师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName2"
                                 label="副主任医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][1].price"
                              class="w-150"
                              placeholder="请输入副主任医师"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName3"
                                 label="主治医师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][2].price"
                              class="w-150"
                              placeholder="请输入主治医师"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </template>
            <!-- 技师 -->
            <template v-if="setCheckType === 2">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][0].price"
                              placeholder="请输入主任技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="副主任技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][1].price"
                              placeholder="请输入副主任技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主管技师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][2].price"
                              placeholder="请输入主管技师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </template>
            <!-- 检验师 -->
            <template v-if="setCheckType === 7">
              <el-table :data="itemList"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主任检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][0].price"
                              placeholder="请输入主任检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="副主任检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][1].price"
                              placeholder="请输入副主任检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="doctorTitleName1"
                                 label="主管检验师">
                  <template slot-scope="scoped">
                    <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setType][2].price"
                              placeholder="请输入主管检验师"
                              class="w-150"></el-input>
                  </template>
                </el-table-column>

              </el-table>
            </template>
          </el-form-item>
        </template>

        <!-- 报告拆分 -->
        <div v-if="formdata.split === 1">
          <el-form-item label="拆分情况111：">
            <el-button type="primary"
                       @click="handleAdd(5)">新 增 一 项</el-button>
            <el-table :data="itemList2"
                      style="width: 100%"
                      border
                      class="mt-20">
              <el-table-column prop="price"
                               label="价格"
                               width="200">
                <template slot-scope="scoped">
                  <el-select v-model="scoped.row.price"
                             placeholder="请选择"
                             clearable
                             @change="(value)=>{upchange(value,scoped.$index)}">
                    <el-option v-for="(item,index) in formdata.itemList"
                               :key="index"
                               :label="`${(item.price || '')+'元'+'/'+(item.num || '')+((item.unit==1?'小时':'次') || '')}`"
                               :value="item.price"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="detectIndies"
                               label="检测项目">
                <template slot-scope="scoped">
                  {{scoped.row.detectIndies}}
                  <!-- <el-select v-model="scoped.row.detectIndies"
                             multiple
                             @change="(value)=>{updataCheckProject(value,scoped.$index)}"
                             placeholder="请选择检测项目">
                    <el-option :label="item.name"
                               :value="item.key"
                               v-for="(item,index) in scoped.row.options"
                               :key="item.key"></el-option>
                  </el-select> -->
                  <el-select v-model="scoped.row.detectIndies"
                             multiple
                             placeholder="请选择检测项目">
                    <el-option :label="item.name"
                               :value="index"
                               v-for="(item, index) in formdata.detectList.filter(row => row.price == scoped.row.price)"
                               :key="index"></el-option>
                  </el-select>

                </template>
              </el-table-column>
              <el-table-column label="是否特殊项目">
                <template slot-scope="scoped">

                  <el-switch v-model="scoped.row.specialItem"
                             active-color="#13ce66"
                             inactive-color="#dcdfe6"
                             :active-value="1"
                             :inactive-value="0">
                  </el-switch>

                </template>
              </el-table-column>
              <el-table-column label="是否执行分析复核流程">
                <template slot-scope="scoped">
                  <el-switch v-model="scoped.row.reCheck"
                             active-color="#13ce66"
                             inactive-color="#dcdfe6"
                             :active-value="1"
                             :inactive-value="0">
                  </el-switch>
                </template>
              </el-table-column>
              <el-table-column header-align="center"
                               align="center"
                               prop="prop"
                               width="120"
                               label="操 作">
                <template slot-scope="scoped">
                  <el-button type="danger"
                             @click='deleteOne1(scoped.$index, itemList2, 3)'>删 除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <el-form-item label="分析分成111：">
            <el-radio-group v-model="setType"
                            @change="changeSetType">
              <el-radio-button :label="0">医 师</el-radio-button>
              <el-radio-button :label="2">技 师</el-radio-button>
              <el-radio-button :label="7">检验师</el-radio-button>
            </el-radio-group>
            <!-- 医师、技师、检验师 -->
            <template>
              <el-table :data="itemList2"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="detectIndies"
                                 label="检测项目">
                  <template slot-scope="scoped">
                    <!--  <el-select v-model="scoped.row.detectIndies"
                               multiple
                               :disabled="true"
                               placeholder="请选择检测项目">
                      <el-option :label="item.name"
                                 :value="item.key"
                                 v-for="(item,index) in scoped.row.options"
                                 :key="index"></el-option>
                    </el-select> -->
                    <el-select v-model="scoped.row.detectIndies"
                               multiple
                               :disabled="true"
                               placeholder="请选择检测项目">
                      <el-option :label="item.name"
                                 :value="index"
                                 v-for="(item,index) in formdata.detectList.filter(row => row.price == scoped.row.price)"
                                 :key="index"></el-option>
                    </el-select>

                  </template>
                </el-table-column>

                <!-- setType === 0 -->
                <template v-if="setType === 0">
                  <el-table-column label="主任医生"
                                   key="0-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                                :placeholder='`请输入主任医生`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任医师"
                                   key="0-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                                :placeholder='`请输入副主任医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主治医师"
                                   key="0-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                                :placeholder='`请输入主治医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="住院医师"
                                   key="0-3">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                                :placeholder='`请输入住院医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="公共卫生执业医师"
                                   key="0-4">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][4].price"
                                :placeholder='`请输入公共卫生执业医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                </template>
                <!-- setType === 2 -->
                <template v-if="setType === 2">
                  <el-table-column label="主任技师"
                                   key="2-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                                :placeholder='`请输入主任技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任技师"
                                   key="2-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                                :placeholder='`请输入副主任技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主管技师"
                                   key="2-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                                :placeholder='`请输入主管技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="技师"
                                   key="2-3">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                                :placeholder='`请输入技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                </template>
                <!-- setType === 7 -->
                <template v-if="setType === 7">
                  <el-table-column label="主任检验师"
                                   key="7-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][0].price"
                                :placeholder='`请输入主任检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任检验师"
                                   key="7-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][1].price"
                                :placeholder='`请输入副主任检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主管检验师"
                                   key="7-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][2].price"
                                :placeholder='`请输入主管检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="检验师"
                                   key="7-3">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][3].price"
                                :placeholder='`请输入检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="检验士"
                                   key="7-4">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setType][4].price"
                                :placeholder='`请输入检验士`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </template>

          </el-form-item>
          <!-- 复核分成 -->
          <el-form-item label="复核分成：">
            <el-radio-group v-model="setCheckType"
                            @change="changeSetCheckType">
              <el-radio-button :label="0">医 师</el-radio-button>
              <el-radio-button :label="2">技 师</el-radio-button>
              <el-radio-button :label="7">检验师</el-radio-button>
            </el-radio-group>
            <!-- 医师、技师、检验师 -->
            <template>
              <el-table :data="itemList2"
                        border
                        style="width: 100%"
                        class="mt-20">
                <el-table-column prop="price"
                                 label="价格"
                                 width="200">
                  <template slot-scope="scoped">
                    <el-tag type="primary">{{(scoped.row.price || '')+'元'+'/'+(scoped.row.num || '')+((scoped.row.unit==1?'小时':'次') || '')}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="detectIndies"
                                 label="检测项目">
                  <template slot-scope="scoped">
                    <el-select v-model="scoped.row.detectIndies"
                               multiple
                               :disabled="true"
                               placeholder="请选择检测项目">
                      <el-option :label="item.name"
                                 :value="index"
                                 v-for="(item,index) in formdata.detectList.filter(row => row.price == scoped.row.price)"
                                 :key="index"></el-option>
                    </el-select>

                  </template>
                </el-table-column>
                <!-- setCheckType === 0 -->
                <template v-if="setCheckType === 0">
                  <el-table-column label="主任医师"
                                   key="0-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][0].price"
                                :placeholder='`主任医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任医师"
                                   key="0-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][1].price"
                                :placeholder='`请输入副主任医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主治医师"
                                   key="0-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][2].price"
                                :placeholder='`请输入主治医师`'
                                class="w-150" />
                    </template>
                  </el-table-column>

                </template>
                <!-- setCheckType===2 -->
                <template v-if="setCheckType === 2">
                  <el-table-column label="主任技师"
                                   key="2-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][0].price"
                                :placeholder='`请输入主任技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任技师"
                                   key="2-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][1].price"
                                :placeholder='`请输入副主任技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主管技师"
                                   key="2-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReadPriceDtosMap[setCheckType][2].price"
                                :placeholder='`请输入主管技师`'
                                class="w-150" />
                    </template>
                  </el-table-column>

                </template>
                <!-- setCheckType===7 -->
                <template v-if="setCheckType === 7">
                  <el-table-column label="主任检验师"
                                   key="7-0">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][0].price"
                                :placeholder='`请输入主任检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="副主任检验师"
                                   key="7-1">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][1].price"
                                :placeholder='`请输入副主任检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>
                  <el-table-column label="主管检验师"
                                   key="7-2">
                    <template slot-scope="scoped">
                      <el-input v-model="scoped.row.healthCheckPackageReCheckPriceDtosMap[setCheckType][2].price"
                                :placeholder='`请输入主管检验师`'
                                class="w-150" />
                    </template>
                  </el-table-column>

                </template>
              </el-table>
            </template>
          </el-form-item>
        </div>
        <el-form-item label="特别说明："
                      prop="specialNote">
          <el-input v-model="formdata.specialNote"
                    maxlength="500"
                    :rows="4"
                    type="textarea"
                    autocomplete="off"
                    show-word-limit
                    style="width:50%"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="医学知识："
                      prop="detectList">
          <el-button type="success"
                     @click="handleAdd(2)">新 增 一 项</el-button>
          <el-table :data="loreList"
                    style="width: 100%"
                    class="mt-20"
                    border>
            <el-table-column prop="name"
                             label="项目名称"
                             width="200">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.name"
                          maxlength="50"
                          autocomplete="off"
                          placeholder="请输入"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="address"
                             label="临床意义">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.clinicalWorth"
                          maxlength="500"
                          :rows="4"
                          type="textarea"
                          autocomplete="off"
                          show-word-limit
                          placeholder="请输入"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="address"
                             label="图片"
                             width="150">
              <template slot-scope="scoped">
                <div @click="op(scoped.$index)">
                  <el-upload class="avatar-uploader"
                             :action="imageUploadUrl"
                             :show-file-list="false"
                             accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                             :on-success="loreListSuccess"
                             :before-upload="beforeAvatarUpload">
                    <img v-if="scoped.row.imageUrl"
                         :src="scoped.row.imageUrl"
                         class="avatar">
                    <i v-else
                       class="el-icon-plus avatar-uploader-icon"></i>
                  </el-upload>
                </div>

              </template>
            </el-table-column>
            <el-table-column prop="address"
                             label="操作"
                             width="100">
              <template slot-scope="scoped">
                <el-button type="text"
                           @click='deleteOne1(scoped.$index,loreList)'>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="医学知识链接："
                      prop="detectList">
          <el-button type="success"
                     @click="handleAdd(3)">新 增 一 项</el-button>
          <el-table :data="loreListOther"
                    style="width: 100%"
                    class="mt-20"
                    border>
            <el-table-column prop="name"
                             label="链接标题">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.name"
                          maxlength="50"
                          autocomplete="off"
                          placeholder="请输入"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="address"
                             label="链接">
              <template slot-scope="scoped">
                <el-input v-model="scoped.row.linkUrl"
                          type="textarea"
                          maxlength="500"
                          :rows="4"
                          autocomplete="off"
                          show-word-limit
                          placeholder="请输入"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="address"
                             label="操作"
                             width="100">
              <template slot-scope="scoped">
                <el-button type="text"
                           @click='deleteOne1(scoped.$index,loreListOther)'>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="复核医生："
                      v-if="formdata.reCheck === 1">
          <reviewDoctorList :hospitalListTableData="hospitalListTableData"></reviewDoctorList>
        </el-form-item>
        <el-form-item label="购买服务后，是否填写健康服务号："
                      label-width="240px">
          <el-radio-group v-model="formdata.isInvitationCode">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <p align="center"
         class="mt-20">
        <el-button @click="$emit('closedialog')">取 消</el-button>
        <el-button type="primary"
                   @click="onSubmit">保 存</el-button>
      </p>
    </el-dialog>

  </div>
</template>

<script>
  import reviewDoctorList from './reviewDoctorList';

  export default {
    props: ['dialogData'],
    data () {
      return {
        dialogVisible: false,
        healthRiskType: [],
        rules: {
          name: [
            { required: true, message: '请填写分类名称' }
          ],
          healthRiskTypeId: [
            { required: true, message: '请选择所属分类' }
          ],
          imageUrl: [
            { required: true, message: '请填上传列表图片' }
          ],
          detailImageUrl: [
            { required: true, message: '请上传详情图片' }
          ],
          itemList: [
            { required: true, message: '请完善服务选项' }
          ],
          standardService: [
            { required: true, message: '请填写标配服务' }
          ],
          hospitalList: [
            { required: true, message: '请选择服务医院' }
          ],
          rangeContent: [
            { required: true, message: '请选择服务医院' }
          ],
          detectList: [
            { required: true, message: '请完善检测项目列表' }
          ],
          specialNote: [
            { required: true, message: '请填写特别说明' }
          ]
        },
        formdata: {
          type: 1,
          imageUrl: null,
          detailImageUrl: [],
          detailImage: [],
          itemList: [{}],
          detectList: [{
            id: 0,
            healthCheckPackageItemId: 0
          }],
          hospitalList: [],
          isInvitationCode: 0,
          split: 1, // 分成设置
          specialItem: 1, // 是否是特殊筛查项目
          reCheck: 1, // 是否执行分析复核流程
        },
        setType: 0,
        setCheckType: 0,
        itemList: [
          {
            healthCheckPackageReadPriceDtosMap: {
              0: [
                { price: null, doctorTitleId: 3, doctorTitleName: "主任医师" },
                { price: null, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                { price: null, doctorTitleId: 6, doctorTitleName: "主治医师" },
                { price: null, doctorTitleId: 7, doctorTitleName: "住院医师" },
                { price: null, doctorTitleId: 32, doctorTitleName: "公共卫生执业医师" }
              ],
              2: [
                { price: null, doctorTitleId: 15, doctorTitleName: "主任技师" },
                { price: null, doctorTitleId: 16, doctorTitleName: "副主任技师" },
                { price: null, doctorTitleId: 17, doctorTitleName: "主管技师" },
                { price: null, doctorTitleId: 18, doctorTitleName: "技师" },
              ],
              7: [
                { price: null, doctorTitleId: 47, doctorTitleName: "主任检验师" },
                { price: null, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                { price: null, doctorTitleId: 49, doctorTitleName: "主管检验师" },
                { price: null, doctorTitleId: 50, doctorTitleName: "检验师" }
              ]
            },
            healthCheckPackageReCheckPriceDtosMap: {
              0: [
                { price: 0.01, doctorTitleId: 3, doctorTitleName: "主任医师" },
                { price: 0.01, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                { price: 0.01, doctorTitleId: 6, doctorTitleName: "主治医师" }
              ],
              2: [
                { price: 0.01, doctorTitleId: 15, doctorTitleName: "主任技师" },
                { price: 0.01, doctorTitleId: 16, doctorTitleName: "副主任技师" },
                { price: 0.01, doctorTitleId: 17, doctorTitleName: "主管技师" }
              ],
              7: [
                { price: 0.01, doctorTitleId: 47, doctorTitleName: "主任检验师" },
                { price: 0.01, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                { price: 0.01, doctorTitleId: 49, doctorTitleName: "主管检验师" }
              ]
            },
          },
        ],

        itemList2: [
          {
            healthCheckPackageReadPriceDtosMap: {
              0: [
                { price: 0.01, doctorTitleId: 3, doctorTitleName: "主任医师" },
                { price: 0.01, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                { price: 0.01, doctorTitleId: 6, doctorTitleName: "主治医师" },
                { price: 0.01, doctorTitleId: 7, doctorTitleName: "住院医师" },
                { price: 0.01, doctorTitleId: 32, doctorTitleName: "公共卫生执业医师" }
              ],
              2: [
                { price: 0.01, doctorTitleId: 15, doctorTitleName: "主任技师" },
                { price: 0.01, doctorTitleId: 16, doctorTitleName: "副主任技师" },
                { price: 0.01, doctorTitleId: 17, doctorTitleName: "主管技师" },
                { price: 0.01, doctorTitleId: 18, doctorTitleName: "技师" }
              ],
              7: [
                { price: 0.01, doctorTitleId: 47, doctorTitleName: "主任检验师" },
                { price: 0.01, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                { price: 0.01, doctorTitleId: 49, doctorTitleName: "主管检验师" },
                { price: 0.01, doctorTitleId: 50, doctorTitleName: "检验师" },
                { price: 0.01, doctorTitleId: 51, doctorTitleName: "检验士" }
              ]
            },
            healthCheckPackageReCheckPriceDtosMap: {
              0: [
                { price: 0.01, doctorTitleId: 3, doctorTitleName: "主任医师", },
                { price: 0.01, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                { price: 0.01, doctorTitleId: 6, doctorTitleName: "主治医师" }
              ],
              2: [
                { price: 0.01, doctorTitleId: 15, doctorTitleName: "主任技师" },
                { price: 0.01, doctorTitleId: 16, doctorTitleName: "副主任技师", },
                { price: 0.01, doctorTitleId: 17, doctorTitleName: "主管技师", }
              ],
              7: [
                { price: 0.01, doctorTitleId: 47, doctorTitleName: "主任检验师", },
                { price: 0.01, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                { price: 0.01, doctorTitleId: 49, doctorTitleName: "主管检验师" }
              ]
            }
          }
        ],
        emphasisHospital: [],
        emphasisHospitalList: [],
        loreList: [{
          type: 1,
        }],
        loreListOther: [{
          type: 2
        }],
        tableData: [{}],
        options1: [],
        dataList: [],
        imageUploadUrl: this.api.appUpgradeUpload.url,
        selectHospitalIds: [],
        whichImg: 0,

        hospitalListTableData: [],
        hospitalListTableDataVisible: false,
        healthCheckPackageDetect: []

      }
    },
    methods: {
      // 拆分情况，分析分成，选择价格重置处理
      upchange (val, key) {
        this.itemList2[key].price = val;
        this.itemList2[key].detectIndies = [];
        this.itemList2[key].options = [];
        this.formdata.detectList.forEach(item => {
          if (item.price === this.itemList2[key].price) {
            this.itemList2[key].options.push(item);
          }
        });
        this.itemList2[key].options.forEach((item, index) => {
          item.key = index;
        })
      },
      // 检测项目选择处理改变值变化
      updataCheckProject (val, key) {
        console.log(val);
        // let options=this.itemList2[key].options,temp=[];
        // if(options.length){
        //   options.forEach((item,index)=>{
        //      if(val.includes(item.key)){
        //        temp.push(index);
        //      }
        //   })
        // }
        this.itemList2[key].detectIndies = val;

      },
      // 检测项目配置 选择价格重置处理
      updataCheckProjectPrice (val, key) {
        this.itemList2.forEach(item => {
          item.detectIndies = []
          // if (val === item.price) {
          //   let subItem = this.formdata.detectList[key];
          //   item.options = [...item.options, ...[subItem]];
          // } else {
          //   item.options = item.oldOptions;
          // }
          // item.options.forEach((subItem, subIndex) => {
          //   subItem.key = subIndex;
          // })
        })
        this.formdata.detectList[key].price = val;
      },
      initTableData (query) {
        let param = {
          name: query,
          pageSize: 300,
          pageIndex: 0
        };
        this.ajax({
          type: this.api.deviceList.type,
          url: this.api.deviceList.url,
          data: param,
          success: (data) => {
            this.dataList = data.object;
          },
          error: (data) => {
            this.$Message.error(data.message);
          }
        });
      },
      // 查询服务医院
      gethospitalList (query) {
        if (query !== '') {
          this.loading1 = true;
          this.post(this.api.cooperationHospital.getServiceHospitalList, { "pageSize": 100, "pageStart": 0, "name": query }).then((res) => {
            this.options1 = res.data.object;
          });
        } else {
          this.options1 = [];
        }
        this.loading1 = false;
      },
      handleAdd (index, options) {
        switch (index) {
          case 0:
            this.formdata.itemList.push({ id: null });
            break
          case 1: // 检测项目配置
            let arr = [], temp = [];
            if (options) {
              this.formdata.detectList.forEach(item => {
                arr.push(item.healthCheckPackageItemId);
                temp.push(item.id);
              })
              this.itemList2.forEach(item => {
                item.oldOptions = item.options;
              })
            }
            this.formdata.detectList.push({
              price: '',
              detectIndies: [],
              id: null,
              healthCheckPackageItemId: null
            });
            break
          case 2:
            this.loreList.push({ type: 1 });
            break
          case 3:
            this.loreListOther.push({ type: 2 });
            break
          case 4:
            break
          case 5:
            this.itemList2.push({
              healthCheckPackageReadPriceDtosMap: {
                0: [
                  { price: 0.01, doctorTitleId: 3, doctorTitleName: "主任医师" },
                  { price: 0.01, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                  { price: 0.01, doctorTitleId: 6, doctorTitleName: "主治医师" },
                  { price: 0.01, doctorTitleId: 7, doctorTitleName: "住院医师" },
                  { price: 0.01, doctorTitleId: 32, doctorTitleName: "公共卫生执业医师" }
                ],
                2: [
                  { price: 0.01, doctorTitleId: 15, doctorTitleName: "主任技师" },
                  { price: 0.01, doctorTitleId: 16, doctorTitleName: "副主任技师" },
                  { price: 0.01, doctorTitleId: 17, doctorTitleName: "主管技师" },
                  { price: 0.01, doctorTitleId: 18, doctorTitleName: "技师" }
                ],
                7: [
                  { price: 0.01, doctorTitleId: 47, doctorTitleName: "主任检验师" },
                  { price: 0.01, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                  { price: 0.01, doctorTitleId: 49, doctorTitleName: "主管检验师" },
                  { price: 0.01, doctorTitleId: 50, doctorTitleName: "检验师" },
                  { price: 0.01, doctorTitleId: 51, doctorTitleName: "检验士" }
                ]
              },
              healthCheckPackageReCheckPriceDtosMap: {
                0: [
                  { price: 0.01, doctorTitleId: 3, doctorTitleName: "主任医师", },
                  { price: 0.01, doctorTitleId: 4, doctorTitleName: "副主任医师" },
                  { price: 0.01, doctorTitleId: 6, doctorTitleName: "主治医师" }
                ],
                2: [
                  { price: 0.01, doctorTitleId: 15, doctorTitleName: "主任技师" },
                  { price: 0.01, doctorTitleId: 16, doctorTitleName: "副主任技师", },
                  { price: 0.01, doctorTitleId: 17, doctorTitleName: "主管技师", }
                ],
                7: [
                  { price: 0.01, doctorTitleId: 47, doctorTitleName: "主任检验师", },
                  { price: 0.01, doctorTitleId: 48, doctorTitleName: "副主任检验师" },
                  { price: 0.01, doctorTitleId: 49, doctorTitleName: "主管检验师" }
                ]
              }
            })
            break
        }
      },
      //更新价格
      updataPrice (e, index, key) {
        console.log(e, index, key);
        this.itemList2[0].healthCheckPackageReadPriceDtosMap[this.setType][index].price = e;
      },
      // 动态删除检测项目配置
      deleteOne1 (index, table, option = false) {
        if (table.length == 1) {
          this.$message.warning('至少保留一项');
          return
        } else {
          let price = table[index].price;
          table.splice(index, 1);
          if (option == 1) {
            this.itemList2.forEach(item => {
              item.options = [];
              if (item.price === price) {
                item.detectIndies = [];
              }
              table.forEach(subItem => {
                if (item.price === subItem.price) {
                  item.options.push(subItem);
                }
              })
            })
          }
          if (option == 2) {
            this.itemList2 = this.itemList2.filter(item => {
              return item.price !== price;
            })
            this.formdata.detectList = this.formdata.detectList.filter(item => {
              return item.price !== price;
            })
          }
          if (option === 3) {
            table.splice(index, 1);
          }
        }
      },
      // 选择服务医院
      changeHospital (val) {
        if (val.length > 0) {
          let newArr = [];
          this.options1.map(item => {
            val.forEach(list => {
              if (item.hospitalId === list) {
                newArr.push({
                  hospitalId: item.hospitalId,
                  hospitalName: item.name,
                  emphasisHospital: item.emphasisHospital
                })
              }
            })
          })
          this.emphasisHospitalList = newArr;
        }
      },

      // 是否是重点合作医院 多选
      checkboxItem (index, item) {
        if (item.emphasisHospital === 0) {
          this.emphasisHospitalList[index].emphasisHospital = 1;
        }
        this.formdata.hospitalList = this.emphasisHospitalList;
      },
      changeSetType (val) {
        this.setType = val;
      },
      changeSetCheckType (val) {
        this.setCheckType = val;
      },


      // 提交保存
      onSubmit () {
        // this.formdata.itemList.forEach(item => {
        //   item.detectList = [];
        //   item.healthCheckPackageSplitItemDtos = [];
        //   this.formdata.detectList.forEach(subItem => {
        //     if (item.price === subItem.price) {
        //       item.detectList.push(subItem);
        //     }
        //   })
        //   this.itemList2.forEach(subItem => {
        //     if (subItem.detectIndies.length > 0) {
        //       subItem.detectIndies = JSON.stringify(subItem.detectIndies).replace(/"/g, '');

        //       if (item.price === subItem.price) {
        //         item.healthCheckPackageSplitItemDtos.push(subItem);
        //       }
        //     }

        //   })
        // })


        /* if (!this.formdata.name) {
          this.$message.warning('请填写分类名称');
          return
        }
        if (!this.formdata.healthRiskTypeId) {
          this.$message.warning('请选择所属分类');
          return
        }
        if (!this.formdata.imageUrl) {
          this.$message.warning('请上传列表图片');
          return
        }
        if (!this.formdata.detailImageUrl) {
          this.$message.warning('请上传详情图片');
          return
        } */
        // 服务选项 判断添加行
        /* let resItemList = this.formdata.itemList
        if (resItemList.length > 0) {
          let itemList = resItemList[resItemList.length - 1]
          if (itemList.price === '' || itemList.price === undefined) {
            this.$message.error('请输入价格');
            return
          }
          if (itemList.unit === '' || itemList.unit === undefined) {
            this.$message.error('请选择单位');
            return
          }
          if (itemList.detectFee === '' || itemList.detectFee === undefined) {
            this.$message.error('请输入检测分成费用');
            return
          }
          if (itemList.extendFee === '' || itemList.extendFee === undefined) {
            this.$message.error('请输入推广分成费用');
            return
          }
        } */

        // 检测项目配置 判断添加行
        /* let resDetectList = this.formdata.detectList;
        if (resDetectList.length > 0) {
          let itemDetectList = resDetectList[resDetectList.length - 1];
          if (itemDetectList.name === '' || itemDetectList.name === undefined) {
            this.$message.error('请输入检查项目');
            return
          }
        } */

        // 医学知识
        this.formdata.loreList = this.loreList.concat(this.loreListOther);
        // 检测项目配置
        /*  this.formdata.itemList.forEach(ele => {
           ele.detectList = []
           this.formdata.detectList.forEach(res => {
             if (res) {
               if (res.healthCheckPackageItemId == ele.id) {
                 ele.detectList.push(res);
               }
             }
           })
           if (ele.id < 0) {
             ele.id = null;
           }
         }) */
        // 详情图片
        this.formdata.detailImageUrl = JSON.stringify(this.formdata.detailImageUrl)
        // 服务医院
        this.formdata.hospitalList = []
        if (this.formdata.hospitalList) {
          this.formdata.hospitalList = this.emphasisHospitalList.map(item => ({
            hospitalId: item.hospitalId,
            emphasisHospital: item.emphasisHospital
          }))
        }

        console.log(this.formdata);

        // return
        if (this.formdata.detailImage) {
          delete this.formdata.detailImage;
        }
        this.formdata.way = 1;
        // 构造数据结构
        const formData = JSON.parse(JSON.stringify(this.formdata))
        const { detectList, itemList } = formData
        const { itemList2 } = this
        const editData = this.editdata
        itemList.forEach(item => {
          item.detectList = detectList.filter(detect => detect.price == item.price).map((detect, i) => {
            detect.detectIndex = i;
            detect.healthCheckPackageItemId = (editData.itemList.find(item => item.price == detect.price) || {}).id;
            return detect
          });
          item.healthCheckPackageSplitItemDtos = itemList2.filter(item2 => item2.price == item.price).map(item => ({
            ...item,
            healthCheckPackageItemId: (editData.itemList.find(itemOld => itemOld.price == item.price) || {}).id,
            detectIndies: JSON.stringify(item.detectIndies)
          }))
        })
        delete formData.detectList;
        console.log(formData);
        // return
        this.post(this.api.cooperationHospital.healthCheckManageuploadInfo, formData).then(res => {
          if (res.data.code === '200') {
            this.$message.success(res.data.message);
            this.$emit('closedialog');
          } else {
            this.$message.warning(res.data.message);
            this.$emit('closedialog');
          }
        })
      },
      op (index) {
        this.whichImg = index;
      },
      loreListSuccess (res) {
        this.loreList.forEach((ele, index) => {
          if (this.whichImg == index) {
            this.$set(ele, 'imageUrl', res.object[0]);
          }
        })
        this.$forceUpdate();
      },
      handleAvatarSuccess (res) {
        this.formdata.imageUrl = res.object[0];
      },
      beforeAvatarUpload (file) {
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isLt2M) {
          this.$message.error('上传图片大小不能超过 2MB!');
        }
        return isLt2M;
      },
      handlePictureCardPreview (res) {
        this.formdata.detailImageUrl.push(res.object[0]);
      },
      onremove (res, list) {
        if (res.response) {
          this.formdata.detailImageUrl = this.formdata.detailImageUrl.filter(ele => ele != res.response.object[0]);
        } else {
          this.formdata.detailImageUrl = this.formdata.detailImageUrl.filter(ele => ele != res.url);
        }
      },
      onexceed () {
        this.$message.warning('详情图片至多上传6张');
      }
    },
    // 详情
    created () {
      this.post(this.api.cooperationHospital.healthRiskTypegetPageList, {
        pageIndex: 0,
        pageSize: 100
      }).then(res => {
        if (res.data.code === '200') {
          this.healthRiskType = res.data.object;
        } else {
          this.$Message.error(res.data.message);
        }
      })
      if (this.dialogData.info) {
        this.post(this.api.cooperationHospital.healthCheckManagegetDetail, {
          id: this.dialogData.info.id
        }).then(res => {
          if (res.data.code === '200') {
            let resData = res.data.object;

            this.editdata = JSON.parse(JSON.stringify(resData));
            this.formdata = resData;
            // this.itemList = resData.itemList;
            this.hospitalListTableData = this.formdata.hospitalList.map(item => ({
              hospitalName: item.hospitalName,
              medicalUnionId: item.medicalUnionId,
              doctorDtos: item.doctorDtos
            }))
            // console.log(this.hospitalListTableData)

            this.formdata.detailImageUrl = JSON.parse(this.formdata.detailImageUrl);
            this.formdata.detailImage = [];

            this.formdata.detectList = [];
            this.itemList2 = [];
            /* this.formdata.detailImageUrl.forEach(ele => {
              let op = {};
              op.name = ele;
              op.url = ele;
              this.formdata.detailImage.push(op);
            }) */
            if (this.formdata.hospitalList) {
              this.formdata.hospitalList.forEach(item => {
                this.emphasisHospitalList.push({
                  hospitalId: item.hospitalId,
                  emphasisHospital: item.emphasisHospital,
                  hospitalName: item.hospitalName
                })
                this.emphasisHospital.push({
                  hospitalId: item.hospitalId,
                  emphasisHospital: item.emphasisHospital,
                  hospitalName: item.hospitalName
                })
                this.gethospitalList(item.hospitalName);
              })

              let str = []
              this.formdata.hospitalList.map(item => {
                str.push(item.hospitalId);
              })
              this.formdata.hospitalList = str;

            }
            // this.healthCheckPackageReadPriceDtosMap = [];
            this.formdata.itemList.forEach((abc, index) => {
              if (abc.detectList) {
                abc.detectList.forEach(op => {
                  this.$set(op, 'price', abc.price);
                  this.formdata.detectList.push(op);
                })
              }
              if (abc.healthCheckPackageSplitItemDtos) {
                abc.healthCheckPackageSplitItemDtos.forEach(item => {
                  this.$set(item, 'price', abc.price);
                  // item.price = abc.price;
                })
              }
              this.itemList2 = [...this.itemList2, ...abc.healthCheckPackageSplitItemDtos]
            })
            this.itemList2.forEach(item => {
              // this.$set(item, 'options', []);
              // this.$set(item, 'oldOptions', []);
              item.detectIndies = JSON.parse(item.detectIndies);
              /*  this.formdata.detectList.forEach(subItem => {
                 if (item.price === subItem.price) {
                   item.options.push(subItem);
                   item.oldOptions = item.options;
                 }
               }) */
            });
            console.log(this.itemList2)
            /* this.itemList2.forEach(item => {
              item.options.forEach((subItem, subIndex) => {
                subItem.key = subIndex;
              });
              item.oldOptions = item.options;
            }) */
            this.initTableData('');
            this.loreList = this.formdata.loreList.filter(ele => ele.type == 1);
            this.loreListOther = this.formdata.loreList.filter(ele => ele.type == 2);
            this.$forceUpdate();
          } else {
            this.$Message.error(res.data.message);
          }
        })

      } else {
        this.initTableData('');
      }
    },
    components: {
      reviewDoctorList
    }
  }
</script>

<style scoped lang="scss">
  .w-150 {
    width: 150px;
  }
  .el-upload-list--picture-card .el-upload-list__item {
    width: 98px !important;
    height: 98px !important;
  }
  .el-upload--picture-card {
    width: 98px !important;
    height: 98px !important;
    line-height: 98px !important;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 98px !important;
    height: 98px !important;
    line-height: 98px !important;
    text-align: center;
  }
  .avatar {
    width: 98px !important;
    height: 98px !important;
    display: block;
  }
  .ivu-select-dropdown {
    z-index: 1000 !important;
  }
</style>
tant;
    text-align: center;
  }
  .avatar {
    width: 98px !important;
    height: 98px !important;
    display: block;
  }
  .ivu-select-dropdown {
    z-index: 1000 !important;
  }
</style>